import React from 'react';
import { Image, ImageProps } from 'antd';

/**
 * @interface Props
 * @param value?: string;
 * @param prefix?: string;
 */
interface Props extends ImageProps {
  value?: string;
  prefix?: string;
}
const errorImage =
  '';
// const downloadUrl = `${process.env.REACT_APP_SERVER_HOST}/{prefix}/com/file/v1/{picId}/download`;
const downloadUrl = `/{prefix}/com/file/v1/{picId}/download`;

/**
 * @name ElImage
 * @description 图片展示组件
 * @param props 
 * @returns 
 */
const ElImage = (props: Props) => {
  const { alt, width = 48, height = 36, prefix = 'yst-b2c' } = props;
  return (
    <Image
      {...props}
      width={width}
      height={height}
      src={
        props.value
          ? downloadUrl
            .replace('{picId}', props.value)
            .replace('{prefix}', prefix)
          : errorImage
      }
      alt={alt}
      fallback={errorImage}
    />
  );
};
export default ElImage;
